<?php
/**
 * Author Yulin
 * Email  dwzhanglong@126.com
 * Date   2017-7-21
 * Func   会员中心
 */
defined('IN_YuLin') || exit('NO PERMIT!');
$seo['title'] = '大众彩票-登录';
$navTag       = 'member';
$page         = 'member/login';
$pageTitle    = '用户登录';
$noShowNav    = true;

// 检查登录操作
$operation    = NoBadStr($_POST['operation']);
if ($operation){
    switch ($operation){
        case 'login':
            $loginSta   = '';
            $username	=	NoBadStr($_POST['username']);
            $password	=	NoBadStr($_POST['password']);
            $user = $db->getrow('SELECT * FROM '.Table('user').' WHERE username = "' . $username . '" AND password = "' . Password($password) . '"');
            $msg  = '';
            if (!$user){
                $msg      = '账号或密码错误';
                $loginSta = false;
                $tpl->display($page);
            }
            // 检查邀请码
            $sql  = 'SELECT invita_code_id FROM ' . Table('user_info') . ' WHERE uid = ' . $user['id'];
            $checkInvita = $db->getrow($sql);
            if ($checkInvita['invita_code_id'] <= 0 || !$checkInvita['invita_code_id']) {
                $msg      = '邀请码出现异常，请联系管理员';
                $loginSta = false;
                $tpl->display($page);
                break;
            }
            
           $_SESSION['userlast'] = $user;
            $_SESSION['uid'] = $user['id'];
            set_cookie('LoginSessionID',session_id());
            header('Location:' . U('member/index'));
            break;
        default:
            break;
    }
    die();
}

// 载入用户基本信息
if ($_user){
    // 用户未登录
    header('Location:index.php');
}



$tpl->display($page);